package com.example.higo.view.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

/**
 * MyBaseQuickAdapter
 * Created by wj on 2016/10/12.
 */

public abstract class MyBaseQuickAdapter extends RecyclerView.Adapter<MyBaseQuickAdapter.BaseViewHolder> {
    Context context;

    public MyBaseQuickAdapter( Context context) {
        this.context = context;
    }

    protected abstract int getLayoutId(int viewType);

    protected abstract void convert(BaseViewHolder holder,int position);

    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(getLayoutId(viewType), parent, false);
        return new BaseViewHolder(view);
    }

    public void onBindViewHolder(BaseViewHolder holder, int position) {
        convert(holder, position);
    }


    @Override
    public abstract int getItemCount();


    public class BaseViewHolder extends RecyclerView.ViewHolder {
        View view;

        public BaseViewHolder(View itemView) {
            super(itemView);
            view = itemView;
        }

        /**
         * setText方法
         */
        public BaseViewHolder setText(int resId, String text) {
            TextView textView = (TextView) view.findViewById(resId);
            textView.setText(text);
            return this;
        }

        /**
         * setImg方法
         */
        public BaseViewHolder setImg(int resId, String path) {
            SimpleDraweeView simpleDraweeView = (SimpleDraweeView) itemView.findViewById(resId);
            simpleDraweeView.setImageURI(path);
            return this;
        }

        /**
         * convertView 方法 得到View 去 findViewById
         *
         * @return
         */
        public View convertView() {
            return view;
        }
    }
}
